﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Donal.Xms.Common;

namespace Donal.Xms.Web.qianyi.users
{
    public partial class user_config : Web.UI.ManagePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ChkAdminLevel("user_config", DTEnums.ActionEnum.View.ToString()); //检查权限
                ShowInfo();
            }
        }

        #region 赋值操作=================================
        private void ShowInfo()
        {
            BLL.userconfig bll = new BLL.userconfig();
            Model.userconfig model = bll.loadConfig();

            regstatus.SelectedValue = model.regstatus.ToString();
            regsmsexpired.Text = model.regsmsexpired.ToString();
            rblVisitors_price_show.SelectedValue = model.visitors_price_show.ToString();
            txtVisitors_discount.Text = model.visitors_discount.ToString();

            if (model.regverify == 1)
            {
                regverify.Checked = true;
            }
            else
            {
                regverify.Checked = false;
            }

            regrulestxt.Text = model.regrulestxt;
        }
        #endregion

        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("user_config", DTEnums.ActionEnum.Edit.ToString()); //检查权限
            BLL.userconfig bll = new BLL.userconfig();
            Model.userconfig model = bll.loadConfig();
            try
            {
                model.regstatus = Utils.StrToInt(regstatus.SelectedValue, 0);
                model.regsmsexpired = Utils.StrToInt(regsmsexpired.Text.Trim(), 0);
                model.visitors_price_show = Utils.StrToInt(rblVisitors_price_show.SelectedValue, 0);
                model.visitors_discount = Utils.ObjToDecimal(txtVisitors_discount.Text, 0);

                if (regverify.Checked == true)
                {
                    model.regverify = 1;
                }
                else
                {
                    model.regverify = 0;
                }

                model.regrulestxt = regrulestxt.Text;

                bll.saveConifg(model);
                AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改用户配置信息"); //记录日志
                JscriptMsg("修改用户配置成功！", "user_config.aspx");
            }
            catch
            {
                JscriptMsg("文件写入失败，请检查是否有权限！", string.Empty);
            }
        }

    }
}